import java.util.*;
public class OurLinkedListTest
{  public static void main (String [] args)
   {  try
     {
      OurLinkedList <String> myList = new OurLinkedList<String>();
      myList.add("A");
      myList.add("B");
      myList.add("C");
      myList.add("B");
      myList.add(2, "X");
      myList.addFirst("Y");
      myList.addLast("Z");
      OurLinkedList <String>cloned = (OurLinkedList<String>)myList.clone();
      System.out.println("Clone of myList: " + cloned);
      System.out.println("myList.contains(X): " + myList.contains("X"));
      System.out.println("myList.contains(D): " + myList.contains("D"));
      System.out.println("myList.get(3): " + myList.get(3));
      System.out.println("myList.getFirst(): " + myList.getFirst());
      System.out.println("myList.getLast(): " + myList.getLast());
      System.out.println("myList.indexOf(B): " + myList.indexOf("B"));
      System.out.println("myList.lastIndexOf(B): " + myList.lastIndexOf("B"));
      System.out.println("myList.remove(3): " + myList.remove(3));
      System.out.println("myList.remove(B) will remove the first B: " + myList.remove("B"));
      System.out.println("myList: " + myList);
      System.out.println("myList.set(2, V): " + myList.set(2, "V"));
      System.out.println("myList.size(): " + myList.size());
      System.out.println("myList: " + myList);
      ListIterator <String> iter = myList.listIterator(2);
      System.out.println("Elements positioned at 2 ~ 5: "); 
      while(iter.hasNext()) System.out.print(iter.next() + " "); 
      System.out.println();
      System.out.println("After removing Z, the last element returned by next");
      iter.remove();
      System.out.println("iter.nextIndex(): " + iter.nextIndex());
      System.out.println();
      System.out.print("All the elements of mylist in a reversed order: "); 
      while(iter.hasPrevious()) System.out.print(iter.previous() + " "); 
      System.out.println();
      iter.remove();
      System.out.println("After removing Y, the last element returned by previous");
      System.out.println("iter.nextIndex(): " + iter.nextIndex());
      System.out.print("All the elements of mylist: ");
      System.out.println(myList);
      System.out.println("iter.hasPrevious(): " + iter.hasPrevious());
      System.out.println("iter.next(): " + iter.next());
      iter.set("T");
      System.out.println("A is replaced by T and iterator lies between T and V");
      System.out.println("All the elements of mylist: ");
      System.out.println(myList);
      System.out.println("iter.next(): " + iter.next());
      System.out.println("Iterator jumped over V, and F will be inserted between V and B, and iterator lies before B");
      iter.add("F");
      
      System.out.println("iter.next(): " + iter.next());
      System.out.println("Iterator jumped over B, and G will be added to the end of list, and iterator lies at the end of list.");
      iter.add("G");
      System.out.println("After adding T and G: "+ myList);
      iter.remove(); 
   }
   catch(IllegalStateException e)
   {  System.out.println("Rule #2 is violated.");
   } 
}
}
